
document.addEventListener('DOMContentLoaded', function() {
    const galleryItems = document.querySelectorAll('.gallery-item');
    const overlay = document.createElement('div');
    overlay.className = 'overlay';
    document.body.appendChild(overlay);

    galleryItems.forEach(item => {
        item.addEventListener('click', function(e) {
            e.stopPropagation();
            const img = this.querySelector('img').cloneNode();
            overlay.innerHTML = '';
            overlay.appendChild(img);
            overlay.classList.add('active');
            document.body.style.overflow = 'hidden'; // 防止背景滚动
        });
    });

    overlay.addEventListener('click', function(e) {
        if (e.target === overlay || e.target.tagName === 'IMG') {
            overlay.classList.remove('active');
            document.body.style.overflow = ''; // 恢复滚动
        }
    });
});
